package com.zxbg.controller.systemtoolsController;

import com.zxbg.controller.Code;
import com.zxbg.controller.Result;
import com.zxbg.domain.Auth;
import com.zxbg.domain.Employee;
import com.zxbg.domain.SystemtoolsLeftMenu;
import com.zxbg.service.systemtoolsService.FunctionalAuthorityService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/FunctionalAuthority")
public class FunctionalAuthorityController {
    @Autowired
    FunctionalAuthorityService functionalAuthorityService;

    @PostMapping
    public Result getAuth(@RequestBody List<String> menu_codes) {
        return new Result(Code.GET_OK, functionalAuthorityService.getAuth(menu_codes));
    }

    @PostMapping("/setAuth")
    public Result setAuth(@RequestBody Map<String, Object> map, @RequestHeader Integer tenant_id) {
        List<SystemtoolsLeftMenu> tempList = map.get("menu") != null && !map.get("menu").equals("") ? (List<SystemtoolsLeftMenu>) map.get("menu") : new ArrayList<>();
        List<Auth> authList = map.get("authority") != null && !map.get("authority").equals("") ? (List<Auth>) map.get("authority") : new ArrayList<>();
        return new Result(Code.UPDATE_OK, functionalAuthorityService.setAuth(tempList, authList, (String) map.get("role_code"), tenant_id));
    }
}
